package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
//zp
@RestController
@RequestMapping("/shopping")
public class IProductCateController {
    @Reference(timeout = 2000, retries = 0, check = false)
    IProductCateService iProductCateService;

    @GetMapping("/categories")
    @Anoymous//无需登录
    //todo 传递什么参数？
    public ResponseData categories(HttpServletRequest httpServletRequest){
        AllProductCateRequest request = new AllProductCateRequest();
        AllProductCateResponse response = iProductCateService.getAllProductCate(request);
        //做一次远程调用了之后要做一次判断  如果没有成功的话，就返回错误Msg
        if(!response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())){
            return new ResponseUtil<>().setErrorMsg(response.getMsg());
        }
        return new ResponseUtil<>().setData(response.getProductCateDtoList());
    }
}
